//
// Created by liuping on 2019/2/14.
//

#include "test_base.h"
#include "boost/any.hpp"
#include <string>

struct A {
    virtual ~A() {
        cout << "destruct A" << endl;
    }
    std::string info = "AAA";
};

struct B {
    virtual ~B() {
        cout << "destruct B" << endl;
    }
    std::string info = "BBB";
};

TEST_F(test_any) {
    boost::any any = A();
    auto v_a = boost::any_cast<A>(any);
    cout << v_a.info << endl;
    any = B();
    auto &v_b = boost::any_cast<B &>(any);
    v_b.info = "bbb bbb";
    const auto &v_b2 = boost::any_cast<const B &>(any);
    cout << v_b2.info << std::endl;
}


TEST_F(catch_any) {
    boost::any f = 1.0f;
    try {
        boost::any_cast<int>(f);
    } catch (boost::bad_any_cast &e) {
        cout << e.what() << endl;
    }

}

TEST_FINSH